#include<iostream>
#define ll long long
using namespace std;

const int N = 1e5 + 10;

int n, m, t;
int a[N], root[N], idx;
struct node
{
    int ls, rs;
    ll sum, add;
}tr[N * 70];

int clone(int x)
{
    int p = ++idx;
    tr[p] = tr[x];
    return p;
}

void lazy(int x, ll v, int len)
{
    tr[x].sum += v * len;
    tr[x].add += v;
}

void pushup(int x) { tr[x].sum = tr[tr[x].ls].sum + tr[tr[x].rs].sum; }

void pushdown(int x, int l, int r)
{
    if (tr[x].add != 0) {
        int mid = (l + r) >> 1;
        tr[x].ls = clone(tr[x].ls);
        tr[x].rs = clone(tr[x].rs);
        lazy(tr[x].ls, tr[x].add, mid - l + 1);
        lazy(tr[x].rs, tr[x].add, r - (mid + 1) + 1);
        tr[x].add = 0;
    }
}

int build(int l, int r)
{
    int p = ++idx;
    tr[p].add = 0;
    if (l == r) tr[p].sum = a[l];
    else {
        int mid = (l + r) >> 1;
        tr[p].ls = build(l, mid);
        tr[p].rs = build(mid + 1, r);
        pushup(p);
    }
    return p;
}

int modify(int x, int l, int r, int ml, int mr, ll v)
{
    int p = clone(x);
    if (l >= ml && r <= mr) lazy(p, v, r - l + 1);
    else {
        int mid = (l + r) >> 1;
        pushdown(p, l, r);
        if (ml <= mid) tr[p].ls = modify(tr[p].ls, l, mid, ml, mr, v);
        if (mr > mid) tr[p].rs = modify(tr[p].rs, mid + 1, r, ml, mr, v);
        pushup(p);
    }
    return p;
}

ll query(int x, int l, int r, int ql, int qr)
{
    if (l >= ql && r <= qr) return tr[x].sum;
    int mid = (l + r) >> 1;
    pushdown(x, l, r);
    ll res = 0;
    if (ql <= mid) res += query(tr[x].ls, l, mid, ql, qr);
    if (qr > mid) res += query(tr[x].rs, mid + 1, r, ql, qr);
    return res;
}

signed main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    t = idx = 0; root[t] = build(1, n);

    char op;
    int x, y, z;
    while (m--) {
        cin >> op;
        if (op == 'C') {
            cin >> x >> y >> z;
            root[t + 1] = modify(root[t], 1, n, x, y, z);
            t++;
        } else if (op == 'Q') {
            cin >> x >> y;
            cout << query(root[t], 1, n, x, y) << '\n';
        } else if (op == 'H') {
            cin >> x >> y >> z;
            cout << query(root[z], 1, n, x, y) << '\n';
        } else if (op == 'B') {
            cin >> z;
            t = z;
        }
    }
}